package com.qly.redis.server.service;

import com.qly.redis.server.entity.UserEntity;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * Created by Andy ye on 2018/8/3.
 */
@Service
public class UserService {

    @Autowired
    RedisTemplate redisTemplate;

    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * 新增
     *
     * @param userEntity
     * @return
     */
    @Transactional
    public void save(String key, String hashKey, UserEntity userEntity) {
        redisTemplate.opsForHash().put(key, hashKey, userEntity);
//        stringRedisTemplate.opsForHash().put(key, hashKey, userEntity);
    }

    /**
     * 查询
     *
     * @return
     */
    public UserEntity getBykey(String key, String hashKey) {

        Object o = redisTemplate.opsForHash().get(key, hashKey);
//        stringRedisTemplate.opsForHash().get(key,hashKey);
        return (UserEntity) o;
    }

}
